﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WXYW.BLL;
using WXYW.Model;

namespace WXYW
{
    public partial class QWXZQDetail : System.Web.UI.Page
    {
        public QWXZQDetailModel Model;
        public List<QWXZQStationModel> StationModels;
        public List<QWXYWPersonModel> PersonModels;
        protected void Page_Load(object sender, EventArgs e)
        {
            switch (ContentView.ActiveViewIndex)
            {
                case 0:
                    BindSummaryData();
                    break;
                case 1:
                    BindStationModels();
                    break;
                case 2:
                    BindPersonModels();
                    break;
            }
            
        }

        private void BindSummaryData()
        {
            if (!IsPostBack)
            {
                for (int startYear = 2010; startYear <= DateTime.Now.Year; startYear++)
                {
                    YearDDL.Items.Add(new ListItem(startYear.ToString(), startYear.ToString()));
                }

                YearDDL.SelectedValue = DateTime.Now.Year.ToString();
                ViewState["Month"] = DateTime.Now.Month;
                ViewState["Year"] = DateTime.Now.Year;

                EnableAllMonthLable();
                switch (DateTime.Now.Month)
                {
                    case 1:
                        LinkButton1.Enabled = false;
                        break;
                    case 2:
                        LinkButton2.Enabled = false;
                        break;
                    case 3:
                        LinkButton3.Enabled = false;
                        break;
                    case 4:
                        LinkButton4.Enabled = false;
                        break;
                    case 5:
                        LinkButton5.Enabled = false;
                        break;
                    case 6:
                        LinkButton6.Enabled = false;
                        break;
                    case 7:
                        LinkButton7.Enabled = false;
                        break;
                    case 8:
                        LinkButton8.Enabled = false;
                        break;
                    case 9:
                        LinkButton9.Enabled = false;
                        break;
                    case 10:
                        LinkButton10.Enabled = false;
                        break;
                    case 11:
                        LinkButton11.Enabled = false;
                        break;
                    case 12:
                        LinkButton12.Enabled = false;
                        break;
                }
            }

            QWXZQService serivce = new QWXZQService();
            Model = serivce.GetQWXZQDetailInfo(Convert.ToInt32(YearDDL.SelectedValue), Convert.ToInt32(ViewState["Month"]));            
        }

        private void BindStationModels()
        {
            QWXZQService service = new QWXZQService();
            StationModels = service.GetQWXZQStationDetailInfo(Convert.ToInt32(ViewState["Year"]), Convert.ToInt32(ViewState["Month"]));
        }

        private void BindPersonModels()
        {
            QWXZQService service = new QWXZQService();
            PersonModels = service.GetQWXZQPersonDetailInfo(Convert.ToInt32(ViewState["Year"]), Convert.ToInt32(ViewState["Month"]));
        }

        protected void LinkButton_Click(object sender, EventArgs e)
        {
            EnableAllMonthLable();
            LinkButton currnetControl = (LinkButton)sender;
            currnetControl.Enabled = false;
            ViewState["Month"] = currnetControl.CommandArgument.ToString();
            QWXZQService serivce = new QWXZQService();
            Model = serivce.GetQWXZQDetailInfo(Convert.ToInt32(YearDDL.SelectedValue), Convert.ToInt32(currnetControl.CommandArgument));
        }

        private void EnableAllMonthLable()
        {
            LinkButton1.Enabled = true;
            LinkButton2.Enabled = true;
            LinkButton3.Enabled = true;
            LinkButton4.Enabled = true;
            LinkButton5.Enabled = true;
            LinkButton6.Enabled = true;
            LinkButton7.Enabled = true;
            LinkButton8.Enabled = true;
            LinkButton9.Enabled = true;
            LinkButton10.Enabled = true;
            LinkButton11.Enabled = true;
            LinkButton12.Enabled = true;
        }

        protected void ExpandPersonButton_Click(object sender, ImageClickEventArgs e)
        {
            SelectedMonthLbl1.Text = string.Format("{0} 年 {1} 月", ViewState["Year"], ViewState["Month"]);
            BindPersonModels();
            ContentView.ActiveViewIndex = 2;
        }

        protected void ExpandStationButton_Click(object sender, ImageClickEventArgs e)
        {
            SelectedMonthLbl.Text = string.Format("{0} 年 {1} 月", ViewState["Year"], ViewState["Month"]);
            BindStationModels();
            ContentView.ActiveViewIndex = 1;
        }

        protected void HideStationButton_Click(object sender, ImageClickEventArgs e)
        {
            BindSummaryData();
            ContentView.ActiveViewIndex = 0;            
        }

        protected void HidePersonButton_Click(object sender, ImageClickEventArgs e)
        {
            BindSummaryData();
            ContentView.ActiveViewIndex = 0;  
        }
    }
}
